package com.ag.hmk.service.impl;

import java.util.List;

import com.ag.bean.TbPlanStandard;
import com.ag.common.IDUtil;
import com.ag.hmk.dao.HmkPlanStandardDAO;
import com.ag.hmk.service.PlanStandardService;

/**
 * 
 * @author hmk
 * 预案启动标准服务实现
 */
public class PlanStandardServImpl implements PlanStandardService {

	private HmkPlanStandardDAO hmkPlanStandardDAO;
	
	//删除
	@Override
	public boolean delete(String psID) {
		boolean flag = false;
		try {
			TbPlanStandard pStandard = this.findByID(psID);
			if (pStandard!=null) {
				pStandard.setA(IDUtil.DELETE);
				hmkPlanStandardDAO.attachDirty(pStandard);
				flag = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			flag = false;
		}
		return flag;
	}

	//查询所有
	@Override
	public List<TbPlanStandard> findAll() {
		List<TbPlanStandard> ps = null;
		try {
			ps = hmkPlanStandardDAO.findByA(IDUtil.PRESERVE);
		} catch (Exception e) {
			e.printStackTrace();
			ps = null;
		}
		return  ps;
		//return hmkPlanStandardDAO.findAll();
	}

	//查询一个
	@Override
	public TbPlanStandard findByID(String psID) {
		TbPlanStandard pStandard = null;
		try {
			if (psID!=null && psID.length()>0) {
				pStandard =  hmkPlanStandardDAO.findById(psID);
			} 
		} catch (Exception e) {
			e.printStackTrace();
			pStandard = null;
		}
		
		return pStandard;
	}
	
	//保存
	@Override
	public boolean save(TbPlanStandard planStandard) {
		boolean flag = false;
		try {
			if (planStandard!=null) {
				planStandard.setA(IDUtil.PRESERVE);
				hmkPlanStandardDAO.attachDirty(planStandard);
				flag = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			flag = false;
		}
		return flag;
	}

	public void setHmkPlanStandardDAO(HmkPlanStandardDAO hmkPlanStandardDAO) {
		this.hmkPlanStandardDAO = hmkPlanStandardDAO;
	}

}
